// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import VueRouter from 'vue-router';
// 引入element UI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import iconPicker from 'vue-fontawesome-elementui-icon-picker' // elementui图标库
import less from 'less'
import App from './App';
// 引入路由
import router, { routes } from './router/index';
// 引入状态管理
import store from './store';
import qs from 'qs'
Vue.prototype.$qs = qs

// 引入echarts
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts

import axios from 'axios';
Vue.prototype.$axios = axios;

import api from "@/api/api.js";
Vue.prototype.$api = api;//请求接口api

import util from "@/common/js/util.js";
import "@/common/js/drag.js"
import exportUtil from "@/common/js/exportUtil.js"
Vue.prototype.$util = util;
Vue.prototype.$exportExcel = exportUtil.exportExcel.bind(exportUtil);

Vue.config.productionTip = false;

import JsonViewer from 'vue-json-viewer'
Vue.use(JsonViewer)

// 使用element UI
Vue.use(ElementUI);
Vue.use(less)
Vue.use(iconPicker)
import './assets/less/public.less'
import './assets/font/iconfont.css'

// 过滤器
// import * as custom from './common/js/util'

// Object.keys(custom).forEach(key => {
//   Vue.filter(key, custom[key])
// })


// 在重写push|replace方法时，先把VueRouter原型对象的push|replace保存一份
let originPush = VueRouter.prototype.push
let originReplace = VueRouter.prototype.replace
// 参数1：告诉原来的push | replace方法，你往那里跳转（传递那些参数）
// 参数2：成功回调
// 参数3：失败回调
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    originPush.call(this, location, resolve, reject)
  } else {
    originPush.call(this, location, () => { }, () => { })
  }
}
VueRouter.prototype.replace = function (location, resolve, reject) {
  if (resolve && reject) {
    originReplace.call(this, location, resolve, reject)
  } else {
    originReplace.call(this, location, () => { }, () => { })
  }
}

new Vue({
  el: '#app',
  router,
  store, //使用store vuex状态管理
  components: { App },
  template: '<App/>',
  data: {
    // 空的实例放到根组件下，所有的子组件都能调用
    Bus: new Vue()
  }
})